import os
from openpyxl import Workbook
import flet as fl
def main(page:fl.Page):
    page.title="批量获取文件名"
    page.window_height=200
    page.window_width=300
    page.horizontal_alignment=fl.MainAxisAlignment.CENTER
    page.vertical_alignment=fl.CrossAxisAlignment.CENTER
    def do_file(e):
        btn.disabled=True
        btn.text="开始读取文件夹"
        folder_path='D:/data'
        final=[]
        for root, dirs, files in os.walk(folder_path):
            for filename in files:
                if '.xlsx' in filename:
                    final.append([filename,""])
        wb=Workbook()
        ws=wb.active
        for i in final:
            ws.append(i)
        wb.save("d:/file_name.xlsx")
        btn.text="已执行完毕"
        btn.color=fl.colors.GREEN
        btn.disabled=False
        page.update()
    btn=fl.ElevatedButton(text="开始读取",width=page.window_width,height=page.window_height*0.7,color=fl.colors.BLUE,bgcolor=fl.colors.YELLOW_100,on_click=do_file)
    page.add(btn)
fl.app(target=main)